﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using CuaHangMayTinh.BusinessEntities;
using CuaHangMayTinh.Utilities;
using DevComponents.DotNetBar;
using CuaHangMayTinh.BusinessLogicLayer;
using System.Threading;

namespace CuaHangMayTinh.PresentationLayer
{
    /// <summary>
    /// form chính của chương trình
    /// </summary>
    public partial class FormChinh : Office2007RibbonForm
    {

        /// <summary>
        /// array lsit quyen cua user
        /// </summary>
        private List<QuyenEntity> quyen;

        private string Title;

        /// <summary>
        /// tạo đối tượng lưu trữ nhân viên hiện hành
        /// </summary>
        public NhanVienEntity NhanVien { get; set; }

        public TaiKhoanEntity TaiKhoan { get; set; }
        /// <summary>
        /// khởi tạo form chính
        /// </summary>
        public FormChinh(NhanVienEntity entity, TaiKhoanEntity taikhoan)
        {
            Thread t = new Thread(() => (new Splash.Splash1("Kiểm tra đăng nhập")).ShowDialog());
            t.Start();
            InitializeComponent();
            NhanVien = entity;
            TaiKhoan = taikhoan;
            t.Abort();
            quyen = QuyenManager.ConvertToList(QuyenManager.Find_IDSubGroupUser(NhanVien.NghiepVu));
            DisableControlForm(quyen.Select(x => x.IDQuyen).ToList());
            Title = this.Text;

            RibbonControl.AddItemToQuickAccessToolbar(btn_DangNhap);
        }

        private void DisableControlForm(List<int> listquyen )
        {
            if (listquyen.Contains(1))
            {
                btn_Backup.Enabled = true;
            }
            if (listquyen.Contains(2))
            {
                btn_Restore.Enabled = true;
            }
            if (listquyen.Contains(3))
            {
                btn_Log.Enabled = true;
            }
            if (listquyen.Contains(4))
            {
                btn_QLUser.Enabled = true;
            }
            if (listquyen.Contains(5))
            {
                btn_hethong_PhanQuyen.Enabled = true;
            }
            if (listquyen.Contains(6))
            {
                btn_KhachHang.Enabled = true;
            }
            if (listquyen.Contains(7))
            {
                btn_NhaCungCap.Enabled = true;
            }
            if (listquyen.Contains(8))
            {
                btn_DonViTinh.Enabled = true;
            }
            if (listquyen.Contains(9))
            {
                btn_LoaiMatHang.Enabled = true;
            }
            if (listquyen.Contains(10))
            {
                btn_ModelMatHang.Enabled = true;
            }
            if (listquyen.Contains(11))
            {
                btn_MatHang.Enabled = true;
            }
            if (listquyen.Contains(12))
            {
                btn_NhanVien.Enabled = true;
            }
            if (listquyen.Contains(13))
            {
                btn_NhapHang.Enabled = true;
            }
            if (listquyen.Contains(14))
            {
                btn_BanHang.Enabled = true;
            }
            if (listquyen.Contains(15))
            {
                btn_XK_TH.Enabled = true;
            }
            if (listquyen.Contains(16))
            {
                btn_BH_SC.Enabled = true;
            }
            if (listquyen.Contains(17))
            {
                buttonItem_hdbanhang.Enabled = true;
            }
            if (listquyen.Contains(18))
            {
                buttonItem_hdnhaphang.Enabled = true;
            }
            if (listquyen.Contains(19))
            {
                buttonItem_hdbaohanhsuachua.Enabled = true;
            }
            if (listquyen.Contains(20))
            {
                buttonItem_hdtrahang.Enabled = true;
            }
            if (listquyen.Contains(21))
            {
                btn_BoPhan.Enabled = true;
            }
            if (listquyen.Contains(22))
            {
                btn_doanhthu.Enabled = true;
            }
            if (listquyen.Contains(23))
            {
                btn_mhbanchay.Enabled = true;
            }
            if (listquyen.Contains(24))
            {
                btn_thongtincuahang.Enabled = true;
            }
        }

        /// <summary>
        /// load form chính
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FormChinh_Load(object sender, EventArgs e)
        {
            toolStripStatusLabelday.Text = string.Format(NhanVien.TenNV + " đang đăng nhập hệ thống.   Ngày {0:dd-MM-yy}", DateTime.Now);
            timer1.Start();
            this.Size = this.MinimumSize;
            toolStripStatusLabeldatetime.Text = string.Format("Thời gian: {0: h:mm:ss tt}", DateTime.Now);
            btn_DangNhap_Click(null, null);
//            MessageBox.Show(DataUtil.StringStartWith("Nguyen Hung ","nguyễn hùng thinh").ToString());
//            string s1 = "Nguyen Hung Thinh";
//            string s2 = "nguyễn hùng";
//            DataUtil.SwapString(ref s1,ref s2);
        }

        /// <summary>
        /// sự kiện nút đăng nhập
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btn_DangNhap_Click(object sender, EventArgs e)
        {
            ribbonControl_hethong.SelectedRibbonTabItem = ribTab_HeThong;
            switch (NhanVien.NghiepVu)
            {
                case 0:
                    ribbonControl_hethong.SelectedRibbonTabItem = ribTab_HeThong;
                    break;
                case 1:
                    ribbonControl_hethong.SelectedRibbonTabItem = ribTab_DanhMuc;
                    break;
                case 2:
                    ribbonControl_hethong.SelectedRibbonTabItem = ribTab_NghiepVu;
                    break;
                case 3:
                    ribbonControl_hethong.SelectedRibbonTabItem = ribTab_BCTK;
                    break;

            }
            if ((Application.OpenForms["FormGiaoDienChinh"] as FormGiaoDienChinh) == null)
            {
                FormGiaoDienChinh frm = new FormGiaoDienChinh();
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormGiaoDienChinh");
        }

        /// <summary>
        /// sự kiện nút đăng xuất
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btn_DangXuat_Click(object sender, EventArgs e)
        {
            if(MessageBox.Show("Bạn có muốn đăng xuất hay không","Thông báo!",MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
            Application.Restart();
        }

        /// <summary>
        /// sự kiện thêm nhà cung cấp
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btn_NhaCungCap_Click(object sender, EventArgs e)
        {
            PhanQuyenEntity phanquyen =
                PhannQuyenManager.ConvertToList(PhannQuyenManager.Find_NhanVien_Quyen(7, NhanVien.MaNV))[0];
            var diem = DataUtil.ConvertBool(phanquyen.Diem);
            if ((Application.OpenForms["FormNhaCungCap"] as FormNhaCungCap) == null)
            {
                FormNhaCungCap frm = new FormNhaCungCap(diem);
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormNhaCungCap");
        }

        /// <summary>
        /// btn sự kiện mở form khách hàng
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btn_KhachHang_Click(object sender, EventArgs e)
        {
            PhanQuyenEntity phanquyen =
                PhannQuyenManager.ConvertToList(PhannQuyenManager.Find_NhanVien_Quyen(6, NhanVien.MaNV))[0];
            var diem = DataUtil.ConvertBool(phanquyen.Diem);
            if ((Application.OpenForms["FormKhachHang"] as FormKhachHang) == null)
            {
                FormKhachHang frm = new FormKhachHang(diem);
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormKhachHang");
        }

        /// <summary>
        /// sự kiện mở form loại mặt hàng
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btn_LoaiMatHang_Click(object sender, EventArgs e)
        {
            PhanQuyenEntity phanquyen =
                PhannQuyenManager.ConvertToList(PhannQuyenManager.Find_NhanVien_Quyen(9, NhanVien.MaNV))[0];
            var diem = DataUtil.ConvertBool(phanquyen.Diem);
            if ((Application.OpenForms["FormLoaiMatHang"] as FormLoaiMatHang) == null)
            {
                FormLoaiMatHang frm = new FormLoaiMatHang(diem);
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormLoaiMatHang");
        }

        /// <summary>
        /// sự kiện mở form modelmặt hàng
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btn_ModelMatHang_Click(object sender, EventArgs e)
        {
            PhanQuyenEntity phanquyen =
                PhannQuyenManager.ConvertToList(PhannQuyenManager.Find_NhanVien_Quyen(10, NhanVien.MaNV))[0];
            var diem = DataUtil.ConvertBool(phanquyen.Diem);
            if ((Application.OpenForms["FormModelMatHang"] as FormModelMatHang) == null)
            {
                FormModelMatHang frm = new FormModelMatHang(diem);
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormModelMatHang");
        }

        /// <summary>
        /// sự kiện mở form nhân viên
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btn_NhanVien_Click(object sender, EventArgs e)
        {
            PhanQuyenEntity phanquyen =
                PhannQuyenManager.ConvertToList(PhannQuyenManager.Find_NhanVien_Quyen(12, NhanVien.MaNV))[0];
            var diem = DataUtil.ConvertBool(phanquyen.Diem);
            if ((Application.OpenForms["FormNhanVien"] as FormNhanVien) == null)
            {
                FormNhanVien frm = new FormNhanVien(diem);
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormNhanVien");
        }

        /// <summary>
        /// sự kiện mở form đơn vị tính
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btn_DonViTinh_Click(object sender, EventArgs e)
        {
            PhanQuyenEntity phanquyen =
                PhannQuyenManager.ConvertToList(PhannQuyenManager.Find_NhanVien_Quyen(8, NhanVien.MaNV))[0];
            var diem = DataUtil.ConvertBool(phanquyen.Diem);
            if ((Application.OpenForms["FormDonViTinh"] as FormDonViTinh) == null)
            {
                FormDonViTinh frm = new FormDonViTinh(diem);
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormDonViTinh");
        }

        /// <summary>
        /// sự kiện mở form mặt hàng
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btn_MatHang_Click(object sender, EventArgs e)
        {
            if ((Application.OpenForms["FormMatHang"] as FormMatHang) == null)
            {
                FormMatHang frm = new FormMatHang();
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormMatHang");
        }

        /// <summary>
        /// sự kiện click sao lưu giữ liệu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btn_Backup_Click(object sender, EventArgs e)
        {
//            string ten = Interaction.InputBox("Nhập tên cần lưu vào!", "Sao lưu dữ liệu");
//            if (BackupRestoreManager.BackUp(ten))
//            {
//                LogBackupRestoreManager.Insert(new LogBackupRestoreEntity())
//            }
            if ((Application.OpenForms["FormBackKup"] as FormBackKup) == null)
            {
                FormBackKup frm = new FormBackKup();
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormBackKup");
        }

        /// <summary>
        /// sự kiện click phục hồi dữ liệu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btn_Restore_Click(object sender, EventArgs e)
        {
            if ((Application.OpenForms["FormRestore"] as FormRestore) == null)
            {
                FormRestore frm = new FormRestore();
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormRestore");
        }

        /// <summary>
        /// sự kiên tich của timer 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            toolStripStatusLabeldatetime.Text = string.Format("Thời gian: {0: h:mm:ss tt}", DateTime.Now);
        }

        /// <summary>
        /// sự kiện click của nhập hàng
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btn_NhapHang_Click(object sender, EventArgs e)
        {
            if ((Application.OpenForms["FormNhapHang"] as FormNhapHang) == null)
            {
                FormNhapHang frm = new FormNhapHang();
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormNhapHang");
        }

        /// <summary>
        /// sự kiện click cảu bán hàng
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btn_BanHang_Click(object sender, EventArgs e)
        {
            if ((Application.OpenForms["FormBanHang"] as FormBanHang) == null)
            {
                FormBanHang frm = new FormBanHang(NhanVien);
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
                this.Text = Title;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormBanHang");
        }

        /// <summary>
        /// sự kiện click của xuất kho trả hàng
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btn_XK_TH_Click(object sender, EventArgs e)
        {
            if ((Application.OpenForms["FormTraHang"] as FormTraHang) == null)
            {
                FormTraHang frm = new FormTraHang(NhanVien);
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
                this.Text = Title;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormTraHang");
        }

        /// <summary>
        /// sự kiện click của bảo hành sửa chữa
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btn_BH_SC_Click(object sender, EventArgs e)
        {
            if ((Application.OpenForms["FormBaoHanhSuaChua"] as FormBaoHanhSuaChua) == null)
            {
                ribbonControl_hethong.SelectedRibbonTabItem = ribTab_NghiepVu;
                FormBaoHanhSuaChua frm;
                try
                {
                    int x = Convert.ToInt32(sender);
                    var dt = BaoHanhSuaChuaManager.GetInfoHoaDon(x);
                    dt.Rows[0][8] = DateTime.Now;
                    dt.Rows[0][9] = "";
                    dt.Rows[0][12] = 0;
                    BaoHanhSuaChuaEntity baoHanhSuaChuaEntity =
                        BaoHanhSuaChuaManager.ConvertToList(dt)[0];
                    frm = new FormBaoHanhSuaChua(baoHanhSuaChuaEntity);
                }
                catch (Exception)
                {
                    frm = new FormBaoHanhSuaChua();
                }
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
                this.Text = Title;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormBaoHanhSuaChua");
        }

        /// <summary>
        /// sự kiện resize của form 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FormChinh_Resize(object sender, EventArgs e)
        {
            if (WindowState == FormWindowState.Minimized)
            {
                this.Hide();
                notifyIcon1.ShowBalloonTip(3000);
            }
        }


        /// <summary>
        /// bắt sự kiện khi double click vào icon
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.Show();
            this.WindowState = FormWindowState.Normal;
            this.StartPosition = FormStartPosition.CenterScreen;
        }

        /// <summary>
        /// click menu hiển thị
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void hienthiFormToolStripMenuItem_Click(object sender, EventArgs e)
        {
            notifyIcon1_MouseDoubleClick(null, null);
        }

        /// <summary>
        /// click menu logout
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void logoutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            btn_DangXuat_Click(sender,e);
        }

        /// <summary>
        /// click menu eixt
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormChinh_FormClosing(this,new FormClosingEventArgs(CloseReason.UserClosing, false));
        }

        /// <summary>
        /// bắt sự kiện khi close form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FormChinh_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                var c = MessageBox.Show(@"Bạn có muốn thoát hay không !", @"Thông báo", MessageBoxButtons.YesNo,
                    MessageBoxIcon.Warning);
                if (c == DialogResult.No)
                {
                    e.Cancel = true;
                }
                else
                {
                    notifyIcon1.Dispose();
                    Environment.Exit(0);
                }
            }
        }

        /// <summary>
        /// bắt sự kiện hóa đơn nhập hàng click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void buttonItem_hdnhaphang_Click(object sender, EventArgs e)
        {
            if ((Application.OpenForms["FormHoaDonNhapHang"] as FormHoaDonNhapHang) == null)
            {
                FormHoaDonNhapHang frm = new FormHoaDonNhapHang();
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
                this.Text = Title;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormHoaDonNhapHang");
        }

        /// <summary>
        /// sự kiện click hóa đơn bảo hành sửa chữa
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void buttonItem_hdbaohanhsuachua_Click(object sender, EventArgs e)
        {
            if ((Application.OpenForms["FormHoaDonBaoHanh"] as FormHoaDonBaoHanh) == null)
            {
                FormHoaDonBaoHanh frm = new FormHoaDonBaoHanh();
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
                this.Text = Title;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormHoaDonBaoHanh");
        }

        /// <summary>
        /// sự kiện click hóa đơn bán hàng
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void buttonItem_hdbanhang_Click(object sender, EventArgs e)
        {
            if ((Application.OpenForms["FormHoaDonBanHang"] as FormHoaDonBanHang) == null)
            {
                FormHoaDonBanHang frm = new FormHoaDonBanHang();
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
                this.Text = Title;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormHoaDonBanHang");
        }

        /// <summary>
        /// sự kiện click hóa đơn trả hàng
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void buttonItem_hdtrahang_Click(object sender, EventArgs e)
        {
            if ((Application.OpenForms["FormHoaDonTraHang"] as FormHoaDonTraHang) == null)
            {
                FormHoaDonTraHang frm = new FormHoaDonTraHang();
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
                this.Text = Title;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormHoaDonTraHang");
        }

        /// <summary>
        /// sự kiện click bộ phận
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btn_BoPhan_Click(object sender, EventArgs e)
        {
            if ((Application.OpenForms["FormBoPhan"] as FormBoPhan) == null)
            {
                FormBoPhan frm = new FormBoPhan();
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
                this.Text = Title;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormBoPhan");
        }

        /// <summary>
        /// sự kiện click phân quyền
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btn_hethong_PhanQuyen_Click(object sender, EventArgs e)
        {
            if ((Application.OpenForms["FormPhanQuyen"] as FormPhanQuyen) == null)
            {
                FormPhanQuyen frm = new FormPhanQuyen();
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
                this.Text = Title;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormPhanQuyen");
        }

        /// <summary>
        /// sự kiện click log
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btn_Log_Click(object sender, EventArgs e)
        {
            if ((Application.OpenForms["FormNhatKyLog"] as FormNhatKyLog) == null)
            {
                FormNhatKyLog frm = new FormNhatKyLog();
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
                this.Text = Title;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormNhatKyLog");
        }

        /// <summary>
        /// sự kiện click quản lý user 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btn_QLUser_Click(object sender, EventArgs e)
        {
            if ((Application.OpenForms["FormTaiKhoan"] as FormTaiKhoan) == null)
            {
                FormTaiKhoan frm = new FormTaiKhoan();
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
                this.Text = Title;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormTaiKhoan");
        }

        /// <summary>
        /// sự kiện click đổi pass
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btn_DoiPass_Click(object sender, EventArgs e)
        {
            if ((Application.OpenForms["FormDoiMatKhau"] as FormDoiMatKhau) == null)
            {
                FormDoiMatKhau frm = new FormDoiMatKhau(TaiKhoan);
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Normal;
                this.Text = Title;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormDoiMatKhau");
        }

        public void buttonItem_thongtin_Click(object sender, EventArgs e)
        {
            PhanQuyenEntity phanquyen =
                PhannQuyenManager.ConvertToList(PhannQuyenManager.Find_NhanVien_Quyen(24, NhanVien.MaNV))[0];
            var diem = DataUtil.ConvertBool(phanquyen.Diem);
            if ((Application.OpenForms["FormInfo"] as FormInfo) == null)
            {
                FormInfo frm = new FormInfo(diem);
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
                this.Text = Title;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormInfo");
        }

        public void btn_mhbanchay_Click(object sender, EventArgs e)
        {
            if ((Application.OpenForms["FormMatHangBanChay"] as FormMatHangBanChay) == null)
            {
                FormMatHangBanChay frm = new FormMatHangBanChay();
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
                this.Text = Title;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormMatHangBanChay");
        }

        public void btn_doanhthu_Click(object sender, EventArgs e)
        {
            if ((Application.OpenForms["FormDoanhThu"] as FormDoanhThu) == null)
            {
                FormDoanhThu frm = new FormDoanhThu();
                frm.MdiParent = this;
                frm.Show();
                frm.WindowState = FormWindowState.Maximized;
                this.Text = Title;
            }
            FormCollection a = Application.OpenForms;
            Library_Controls.ShowMDI(a, "FormDoanhThu");
        }

        /// <summary>
        /// sự kiện click trợ giúp
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btn_TroGiup_Click(object sender, EventArgs e)
        {
            string filePath = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryNameư(Application.StartupPath)),
                "Help.chm");
            if (File.Exists(filePath))
            {
                ProcessStartInfo pi = new ProcessStartInfo(filePath);
                Process.Start(pi);
            }
        }

    }
}
